package org.cnc.explain.lifecycle.hookbean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * <p>
 * #TODO: desc
 * </p>
 *
 * @author zhiyong.tan
 * @since 2022-09-14
 */
@Component
public class HookBeanPostProcessor implements BeanPostProcessor {

	@Override
	@SuppressWarnings(" NullableProblems")
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		if (PrintHelper.beanNameSatisfied(beanName)) {
			PrintHelper.printMsgWithStep("执行 BeanPostProcessor#postProcessBeforeInitialization 回调");
		}
		return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
	}

	@Override
	@SuppressWarnings(" NullableProblems")
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		if (PrintHelper.beanNameSatisfied(beanName)) {
			PrintHelper.printMsgWithStep("执行 BeanPostProcessor#postProcessAfterInitialization 回调");
		}
		return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
	}
}
